package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CasePic;
import com.ruoyi.system.service.ICasePicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案件图片Controller
 * 
 * @author ruoyi
 * @date 2021-04-07
 */
@RestController
@RequestMapping("/system/casepic")
public class CasePicController extends BaseController
{
    @Autowired
    private ICasePicService casePicService;

    /**
     * 查询案件图片列表
     */
    @PreAuthorize("@ss.hasPermi('system:casepic:list')")
    @GetMapping("/list")
    public TableDataInfo list(CasePic casePic)
    {
        startPage();
        List<CasePic> list = casePicService.selectCasePicList(casePic);
        return getDataTable(list);
    }

    /**
     * 导出案件图片列表
     */
    @PreAuthorize("@ss.hasPermi('system:casepic:export')")
    @Log(title = "案件图片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CasePic casePic)
    {
        List<CasePic> list = casePicService.selectCasePicList(casePic);
        ExcelUtil<CasePic> util = new ExcelUtil<CasePic>(CasePic.class);
        return util.exportExcel(list, "casepic");
    }

    /**
     * 获取案件图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:casepic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(casePicService.selectCasePicById(id));
    }

    /**
     * 新增案件图片
     */
    @PreAuthorize("@ss.hasPermi('system:casepic:add')")
    @Log(title = "案件图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CasePic casePic)
    {
        return toAjax(casePicService.insertCasePic(casePic));
    }

    /**
     * 修改案件图片
     */
    @PreAuthorize("@ss.hasPermi('system:casepic:edit')")
    @Log(title = "案件图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CasePic casePic)
    {
        return toAjax(casePicService.updateCasePic(casePic));
    }

    /**
     * 删除案件图片
     */
    @PreAuthorize("@ss.hasPermi('system:casepic:remove')")
    @Log(title = "案件图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(casePicService.deleteCasePicByIds(ids));
    }
}
